/**
 * NewTaskDialog.java
 * @author: liuex
 * 2007-12-31 ����12:47:16
 *
 * note: 
 */
package lex.mtd.ui.download;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.lex.swing.widgets.EnhancedDialog;




import lex.mtd.core.DownloadObject;

public class NewTaskDialog extends EnhancedDialog
{
	public static DownloadObject showDialog( Window root )
	{
		NewTaskDialog d = new NewTaskDialog( root );
		d.setSize( 350, 375 );
		d.setLocationRelativeTo( root );
		d.setVisible( true );
		return d.task;
	}

	private NewTaskPane pane = null;
	private DownloadObject task = null;

	public NewTaskDialog( Window root )
	{
		super( root, "New Task", true );
		this.initialize();
	}

	@Override
	public void cancel()
	{
		task = null;
		this.dispose();
	}

	private void initialize()
	{
		this.setContentPane( this.getPane() );
		this.setDefaultButton( this.getPane().getOkButton() );
	}

	private NewTaskPane getPane()
	{
		if( null == pane )
		{
			pane = new NewTaskPane();
			pane.getCancelButton().addActionListener( new ActionListener(){
				@Override
				public void actionPerformed( ActionEvent e )
				{
					cancel();
				}				
			} );
			pane.getOkButton().addActionListener( new ActionListener(){

				@Override
				public void actionPerformed( ActionEvent e )
				{
					task = pane.createDownloadTask();
					dispose();
				}
				
			} );
		}
		return pane;
	}
}
